package com.four.shop.service.impl;

import com.four.shop.dao.PropertyDao;
import com.four.shop.entity.Property;
import com.four.shop.service.PropertyService;
import com.four.shop.vo.FormatVo;
import com.guli.common.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Author:wsy
 * @Date: 2021/12/9/15:35
 */
@Service
public class PropertyServiceImpl implements PropertyService {

    @Autowired
    private PropertyDao propertyDao;


    @Override
    public PageUtils propertyList(Map <String, Object> map) {
        //page  当前页
        Integer page = Integer.valueOf((String) map.get("page")==null?"1":(String) map.get("page"));
        //limit  每页多少条
        Integer limit = Integer.valueOf((String) map.get("limit")==null?"3":(String) map.get("limit"));
        //规格搜索
        String formShop = (String) map.get("formShop");
        //查一遍总条数
        List<FormatVo> list = propertyDao.getList();
        //第几页第几条开始
        int size = (page-1)*limit;
        //获取分页后的列表
        List<FormatVo> getList = propertyDao.propertyList(size, limit,formShop);
        //获取分页对象
        PageUtils pageUtils = new PageUtils(getList, list.size(), limit, page);
        return pageUtils;
    }

    @Override
    public void delBatch(String ids) {
        //分割
        String [] split=ids.split(",");
        //创建一个集合
        ArrayList<Integer> idsList = new ArrayList<>();
        //遍历split字符串数组
        for (String s : split) {
            int i=0;
            //讲String字符串类型数据转换成Integer整形数据
            i=Integer.parseInt(s);
            idsList.add(i);
        }
        for (Integer idss : idsList) {
            propertyDao.delBatch(idss);
        }
    }

    /**
     * 前台传过来的是数组
     * 批量删除
     * @param asList
     */
    @Override
    public void delBatch2(List<Integer> asList) {
        for (Integer ids : asList) {
            propertyDao.delBatch(ids);
        }
    }
    /**
     * 添加2
     *
     * @param property
     *
     * @return
     */
    @Override
    public void propertyadd3(Property property) {
        propertyDao.propertyadd3(property);
    }

}
